package org.example.opus.controller;


import feign.form.FormData;
import io.swagger.v3.oas.annotations.Operation;
import org.example.ai.model.entity.Users;
import org.example.ai.model.entity.Works;
import org.example.ai.result.Result;
import org.example.ai.util.AuthContextHolder;
import org.example.opus.login.RedisTokenLookup;
import org.example.opus.service.IUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 作品表，存储用户发布的作品信息及相关属性 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-01-17
 */
@RestController
@RequestMapping("/users")
@CrossOrigin
public class UsersController {

    @Autowired
    private IUsersService usersService;
    @Operation(summary = "作品列表")
    @GetMapping("/usersList")
    public List<Users> usersList(){
        return usersService.list();
    }


    @Operation(summary = "昵称修改")
    @PostMapping ("/getWorkUpdate")
    @RedisTokenLookup
    public int getWorkUpdate(@RequestBody Users users){
        Long userId = AuthContextHolder.getUserId();
        users.setUserId(Math.toIntExact(userId));
        return usersService.getWorkUpdate(users);
    }

    @Operation(summary = "头像修改")
    @PostMapping ("/getUpdate")
    @RedisTokenLookup
    public int getUpdate(Integer userId,String avatar){
//        Long userId = AuthContextHolder.getUserId();
//        users.setUserId(Math.toIntExact(userId));
        return usersService.getUpdate(userId, avatar);
//        return 200;
    }



}
